<%@page import="com.jfinal.kit.PropKit" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>积分抵现</title>
    <jsp:include page="../../include/header.jsp"></jsp:include>
     <style type="text/css">
      input{outline:none;}
      .control-label {
	    padding-top: 7px;
	    margin-bottom: 0;
	    text-align: right;
	 }
	 .form-controls {
	    border: 1px solid #e5e6e7;
	    border-radius: 1px;
	    color: inherit;
	    width: 50%;
	    padding: 6px 12px;
	    font-size: 14px;
	}
	.btns{
		margin-top:50px;
	}
	.sss{
		margin-top: 20px;
		margin-bottom: 20px;
	}
	.aaa{
		margin-top: 20px;
		margin-bottom: 20px;
	}
	.row{
		margin-top: 20px;
	}
	</style>
</head>
<body>
	<div id="wrapper" class="row">
		<h1 class="page-header">积分抵现</h1>		
			<!-- 搜索框 -->
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label">会员手机号：</label>
				    <div class="col-sm-9">
			        	<input type="text" id="phone" name="phone"  class="form-controls" placeholder="手机号"   maxlength="30">
			        	<button  class="btn btn-success" onclick="search();">查询</button>
				    </div>
				</div>
			</div>
			<div class="sss">
				<div class="row aaa">
					 <div class="form-group">
					    <label class="col-sm-2 control-label"></label>
					    <div class="col-sm-9">
				        	<span style="font-weight:bold;">姓名：</span><span id="sname"></span>
					  
					    	<c:if test="${record.point==1 }">
					        	<span style="font-weight:bold;" >积分：</span>
					    	</c:if>
					    	<c:if test="${record.point==2 }">
					        	<span style="font-weight:bold;" >抵扣券：</span>
					    	</c:if>
					    	<c:if test="${record.point==3 }">
					        	<span style="font-weight:bold;" >惠券：</span>
					    	</c:if>
				        	<span id="point"></span>
					    </div>
					</div>
				</div>
			
			</div>
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label">消费项目：</label>
				    <div class="col-sm-9">
			        	<input type="text" id="mun" name="mun"  class="form-controls"  maxlength="100">
				    </div>
				</div>
			</div>
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label">本次总消费：</label>
				    <div class="col-sm-9">
			        	<input type="text" id="money" name="money" onkeyup="changemoney(this);" class="form-controls">&nbsp;&nbsp;元<br/>
			        	<label class="">本次最多可抵现<span id="zdzx"></span></label>
				    </div>
				</div>
			</div>
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label">你目前最多可抵现积分：</label>
				    <div class="col-sm-9">
			        	<input type="text" id="amount" name="amount"  class="form-controls" readonly="readonly">
				    </div>
				</div>
			</div>
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label">抵现后金额：</label>
				    <div class="col-sm-9">
			        	<input type="text" id="amounts" name="amounts"  class="form-controls" readonly="readonly">&nbsp;&nbsp;元<br/>
				    </div>
				</div>
			</div>
			<div class="row">
				 <div class="form-group">
				    <label class="col-sm-2 control-label"></label>
				    <div class="col-sm-9">
			        	<button  class="btn btn-success search-btn btns" onclick="query();">抵现</button>
			        	<input type="hidden" id="point" name="point"  class="form-controls" readonly="readonly"  value="${record.point}">
			        	<input type="hidden" id="dixian" name="dixian"  class="form-controls" readonly="readonly" value="${record.point}">
			        	<input type="hidden" id="storeid" name="storeid"  class="form-controls" readonly="readonly" value="${record.storeid}">
				    </div>
				</div>
			</div>
	    </div>


<jsp:include page="../../include/javascripts.jsp"></jsp:include>
<script type="text/javascript">
var detailDialog;
var type= $("#point").val();
var kou= $("#dixian").val();
var storeid= $("#storeid").val();
function search(){
	var phone = $("#phone").val();
	if(phone==null ||phone==""||phone==undefined){
		Kit.alert("请输入手机号");return;
	}else{
	 	$.post("${BASE_PATH}/bus/order/phone",{'phone':phone},function(result){
			 if(result.flag==0){
				 $("#sname").html(result.object.name);
				 if(type==1){
					 $("#point").html(result.object.sppoint);
				 }else if(type==2){
					 $("#point").html(result.object.jkpoint);
				 }else if(type==3){
					 $("#point").html(result.object.jypoint);
				 }
			 }else{
				window.location.reload(true);
			 }
		}); 
	}
}
function changemoney(obj){
	obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
	obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个, 清除多余的
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
	var money=parseFloat($("#money").val());
	var zsmoney=money*kou;
	var zmoney=parseFloat(zsmoney.toFixed(0));
	$("#zdzx").html(zmoney);
	 var point =$("#point").text();
	 if(point==null ||point==""||point==undefined){
		 point=0;
	 }
	 var points=parseInt(point);
	 if(point<zmoney){
		 $("#amount").val(point);
	 }else{
		 $("#amount").val(zmoney);
	 }
	 var amount=parseInt($("#amount").val());
	 $("#amounts").val(money-amount);
	
 } 
 function query(){
	 var params = {
		phone:$("#phone").val(),//会员手机号
		name:$("#sname").html(),//会员姓名
		mun:$("#mun").val(),//消费项目
		money:$("#money").val(),
		amount:$("#amount").val(),//抵现积分
		amounts:$("#amounts").val(),
		storeid:storeid,
		type:type
	};
	 $.post("${BASE_PATH}/bus/order/savedixian",params,function(result){
			if(result.flag==0){
				window.location.href="${BASE_PATH}/bus/order/dixianlist";
			}else{
				Kit.alert("操作失败");return;
			}
			
		});
 }
</script>
</body>
</html>